
use data_study_1.dta, clear


// Set omitted categories
	gen zero_race = 0
	label var zero_race "White"
	gen zero_sex = 0
	label var zero_sex "Male"
	gen zero_eco = 0
	label var zero_eco "Maintain investment in energy"
	
// Set regression variables
	loc reg_race "cand_black zero_race"
	loc reg_sex "cand_female zero_sex"
	loc reg_issues "cand_policy_abort1 cand_policy_abort2 cand_policy_tax1 cand_policy_tax2"
	loc reg_issues "`reg_issues' cand_policy_health1 cand_policy_health2 cand_policy_eco1 zero_eco"
	loc reg_affirm "cand_policy_aa1 cand_policy_aa2 cand_policy_aa3"
	
// Interactive Terms for Black Candidate X Affirmative Action
	gen noracepolicy = cand_policy_aa1 == 0 & cand_policy_aa2 == 0 & cand_policy_aa3 == 0	
	gen black_aa1 = cand_policy_aa1*cand_black
	gen black_aa2 = cand_policy_aa2*cand_black
	gen black_aa3 = cand_policy_aa3*cand_black
	gen white_aa1 = cand_policy_aa1*cand_white
	gen white_aa2 = cand_policy_aa2*cand_white
	gen white_aa3 = cand_policy_aa3*cand_white
	gen black_aa0 = noracepolicy*cand_black
	gen white_aa0 = noracepolicy*cand_white
	label var black_aa0 "Black X No Position"
	label var white_aa0 "White X No Position"
	label var black_aa1 "Black X Expand (race)"
	label var black_aa2 "Black X Keep as is"
	label var black_aa3 "Black X Replace (class)"
	label var white_aa1 "White X Expand (race)"
	label var white_aa2 "White X Keep as is"
	label var white_aa3 "White X Replace (class)"
	replace white_aa0 = 0
	label var noracepolicy "Not shown position"
	loc int "white_aa0 black_aa0 white_aa1 white_aa2 white_aa3 black_aa1 black_aa2 black_aa3"
	

//============================================================================== Liberalness


	// Panel (i)
		reg out_ideo_econ `reg_sex' `reg_issues' `int' cand_age, robust
		eststo ideo_econ
		reg out_ideo_soc `reg_sex' `reg_issues' `int' cand_age, robust
		eststo ideo_soc
		
	// Panel (ii)
		reg out_policy_tanf `reg_sex' `reg_issues' `int' cand_age, robust
			eststo policy_tanf
		reg out_policy_minwage `reg_sex' `reg_issues' `int' cand_age, robust
			eststo policy_minwage
		reg out_policy_repar `reg_sex' `reg_issues' `int' cand_age, robust
			eststo policy_repar
	
	

	// i
		coefplot (ideo_econ, label() mc(gs4) ciopts(color(gs4) lw(med))) ///
					, bylabel("{bf:(a) Economic Liberalness}") || ///
				 (ideo_soc, label() mc(gs4) ciopts(color(gs4) lw(med))) ///
					, bylabel("{bf:(b) Social Liberalness}") ///
				|| , drop(_cons `reg_sex' `reg_issues' cand_age) omitted baselevels ms(c) msize(med) ///
				ylabel(,labsize(vsmall)) ///
			xline(0, lc(black)) nokey ///
			subtitle(, bcolor(white) color(black) size(vsmall)) ///
			byopts(row(1) t1title("{bf:(i) Inferred Liberalness by Dimension}", size(small))) ///
			xtitle("Effects of Candidate Attributes (Scale 0 to 1)", size(vsmall)) ///
			xlabel(-0.2(0.1)0.2,labsize(small)) norecycle ///
			headings(white_aa0 = "{bf: No Affirmative Action}" ///
				white_aa1 = "{bf: White Affirmative Action}" ///
				black_aa1 = "{bf: Black X Affirmative Action}", labsize(vsmall)) saving(s1_1.gph, replace)

	// ii
		coefplot (policy_tanf, label() mc(gs4) ciopts(color(gs4) lw(med))) ///
					, bylabel("{bf:(c) TANF}") || ///
				 (policy_minwage, label() mc(gs4) ciopts(color(gs4) lw(med))) ///
					, bylabel("{bf:(d) Minimum Wage}") || ///
				(policy_repar, label() mc(gs4) ciopts(color(gs4) lw(med))) ///
					, bylabel("{bf:(e) Reparations}") ///
				|| , drop(_cons `reg_sex' `reg_issues' cand_age) omitted baselevels ms(c) msize(med) ///
				ylabel(,labsize(vsmall)) ///
			xline(0, lc(black)) nokey ///
			subtitle(, bcolor(white) color(black) size(vsmall)) ///
			byopts(row(1) t1title("{bf:(ii) Inferred Liberalness on Other Issues}", size(small))) ///
			xtitle("Effects of Candidate Attributes (Scale 0 to 1)", size(vsmall)) ///
			xlabel(-0.2(0.1)0.2,labsize(small)) norecycle ///
			headings(white_aa0 = "{bf: No Affirmative Action}" ///
				white_aa1 = "{bf: White Affirmative Action}" ///
				black_aa1 = "{bf: Black X Affirmative Action}", labsize(vsmall)) saving(s1_2.gph, replace)
				
		graph combine s1_1.gph s1_2.gph, rows(2) imargin(0)
		
	graph export figure_s1.png, as(png) replace